//
//  SqliteManager.swift
//  SQLite学习
//
//  Created by 袁飞霞 on 16/5/17.
//  Copyright © 2016年 cn.sophietobeabetterone. All rights reserved.
//

import UIKit


// sqlite 操作 
// 打开数据库 
//创建表
//操作数据

class SqliteManager: NSObject {
     static let sharedManager = SqliteManager()
    private override init() {
       
        let dbpath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory,
            NSSearchPathDomainMask.UserDomainMask, true).last?.stringByAppendingString("/sqlite.db")
        var db:COpaquePointer = nil
      if  sqlite3_open(dbpath!, &db) == SQLITE_OK
      {
        print("打开成功")
        
    }
        let sql = "CREATE TABLE IF NOT EXISTS T_Person (id INTERGER PRIMARY KEY AUTOINCREMENT,name TEXT,age INTEGER,height REAL)"
        var error:UnsafeMutablePointer<Int8> = nil
        if sqlite3_exec(db, sql, nil, nil, &error) == SQLITE_OK
        {
            print("表创建成功")
        }else
        {
        print(error)
        }
        
    }
    
}
